package model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.*;

/**
 * The persistent class for the seats database table.
 * 
 */
@Entity
@Table(name = "seats")
@NamedQueries({
		@NamedQuery(name = "Seat.findAll", query = "SELECT s FROM Seat s"),
		@NamedQuery(name = "Seat.findAllUser", query = "SELECT s FROM Seat s WHERE s.user.id= :userId GROUP BY s.user.id, s.projection.id"),
		@NamedQuery(name = "Seat.findAllUserSold", query = "SELECT s FROM Seat s WHERE s.user.id= :userId AND s.sold=true GROUP BY s.user.id, s.projection.id"),
		@NamedQuery(name = "Seat.findAllProjection", query = "SELECT s.id.seatNumber FROM Seat s WHERE s.user.id= :userId AND s.projection.id= :projectionId"),
		@NamedQuery(name = "Seat.findAllProjectionSold", query = "SELECT s.id.seatNumber FROM Seat s WHERE s.user.id= :userId AND s.projection.id= :projectionId AND s.sold=true"),
		@NamedQuery(name = "Seat.findSeatsPrice", query = "SELECT (COUNT(*)*s.projection.price) FROM Seat s WHERE s.user.id= :userId AND s.projection.id= :projectionId AND s.sold=true"),
		@NamedQuery(name = "getSeatsByProjectionId", query = "SELECT p.seats from Projection p where p.id = :id") })
public class Seat implements Serializable {
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private SeatPK id;

	// bi-directional many-to-one association to Projection
	@ManyToOne
	@JoinColumn(name = "projection_id", nullable = false, insertable = false, updatable = false)
	private Projection projection;

	// bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name = "user_id", nullable = true)
	private User user;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "locked", nullable = false, length = 19)
	private Date locked;

	@Column(name = "sold", nullable = false)
	private boolean sold;

	@Column(name = "attended", nullable = false)
	private boolean attended;

	public Seat() {
	}

	public SeatPK getId() {
		return this.id;
	}

	public void setId(SeatPK id) {
		this.id = id;
	}

	public Projection getProjection() {
		return this.projection;
	}

	public void setProjection(Projection projection) {
		this.projection = projection;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Date getLocked() {
		return this.locked;
	}

	public void setLocked(Date locked) {
		this.locked = locked;
	}

	public boolean isSold() {
		return this.sold;
	}

	public void setSold(boolean sold) {
		this.sold = sold;
	}

	public boolean isAttended() {
		return this.attended;
	}

	public void setAttended(boolean attended) {
		this.attended = attended;
	}

}